package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import controllers.DBConnection;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;

import javax.swing.LayoutStyle.ComponentPlacement;

import messages.SearchPicMessage;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class Archive_Managing extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Archive_Managing frame = new Archive_Managing();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the Archive_Managing frame.
	 */
	public Archive_Managing() {
		setTitle("Archive Managing");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 629, 365);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JButton btnNewButton = new JButton("Add new Image");
		btnNewButton.setBounds(15, 16, 162, 53);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
		
				Add_Pic_worker frame = new Add_Pic_worker();
				frame.setVisible(true);
				try{
					 
					 /*insert image*/
					 DBConnection conn1=new DBConnection();
					
					String finaly=("Samples//6001.jpg");
						
					 	 File file = new File(finaly); //"images/**.jpg
					     FileInputStream fis = new FileInputStream(file);
					     int len = (int)file.length();
						 System.out.println("-----   "+len);
					     java.sql.PreparedStatement pr7= conn1.getDBConnection().prepareStatement("INSERT INTO  sgi_system.sample  VALUES(?,?,?)");
					     
					     pr7.setString(1,file.getName());
					     pr7.setInt(2, len);

					     // Method used to insert a stream of bytes
					     pr7.setBinaryStream(3, fis, len); 
					     pr7.executeUpdate();
					     
					    JOptionPane.showMessageDialog(null, "picture was added");
			}
				catch (Exception e)
				{
				
						e.printStackTrace();
					
				}
			}	
	
		});
		
		JButton btnNewButton_1 = new JButton("Delete image");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton_1.setBounds(15, 112, 162, 55);
		
		JButton btnNewButton_2 = new JButton("Edit user");
		btnNewButton_2.setBounds(15, 191, 162, 62);
		contentPane.setLayout(null);
		contentPane.add(btnNewButton_1);
		contentPane.add(btnNewButton);
		contentPane.add(btnNewButton_2);
		
		JButton button = new JButton("Back");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				WorkerGUI frame = new WorkerGUI();
				frame.setVisible(true);
				dispose();
			}
		});
		
		JButton btnNewButton_3 = new JButton("Cancel");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		

		btnNewButton_3.setBounds(40, 278, 118, 23);
		contentPane.add(btnNewButton_3);
		
	
		button.setBounds(168, 278, 118, 23);
		contentPane.add(button);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon("images//Silver.jpg"));
		lblNewLabel.setBounds(0, 0, 613, 326);
		contentPane.add(lblNewLabel);
		lblNewLabel.setLayout(null);
	}
}
